import Vue from 'vue';
import api from "../../api/api.js"
import routerUtil from "../../router/routerUtil.js"

const sys = {
    state: {
        added: false, // 加载路由标志
        menuList: null, // 顶部菜单
		activeMenu:null,
		userInfo:{
			nickName:"昵称",
			headUrl:"头像",
			loginName:"登陆名",
			phone:"13716343106",
			roleNames:"",
			permissionList:[],
			roleList:[]
		},
		tagsShowViewList:[]
    },
    mutations: {
        updateMenulist(state, menuList) {
            state.menuList = menuList;
        },
		updateUserInfo(state, userInfo) {
			if(userInfo.roleNameList){
				userInfo.roleNames = userInfo.roleNameList.join(",")
			}else{
				userInfo.roleNames = ''
			}
			state.userInfo = userInfo
		},
    },
	actions: {
		generateRoutes({ commit }) {
			return new Promise(resolve => {
				
				api.sysMenuFindUserMenuByTree().then(result => {
					let menuList = result
					//配置路由
					const otherRoutes = []
					routerUtil.initRouterNode(otherRoutes, menuList)
					
					//添加所有菜单
					commit('updateMenulist', menuList);
					
					resolve(otherRoutes)
				})
			})
		},
		
	}
};

export default sys;
